<extend name="common/base" />
<block name="main">
    <form action="<if condition="$info">{:url('update')}<else/>{:url('insert')}</if>" id="j_custom_form" callback="TabAjaxDone" class="col-md-12 form-label-right center-margin form-validate" method="post" noEnter>
        <input type="hidden" name="catid" value="{$info.catid}" />
        <div class="pageContainer">
            <div class="form-row">
                <div class="form-label col-md-2"><label>分类名：</label>
                </div>
                <div class="form-input col-md-7">
                    <input type="text" size="30" class="validate[required,minSize[3]] required"  name="catname" id="j_name" value="{$info.catname}"  >
                </div>
            </div>
            <div class="form-row">
                <div class="form-label col-md-2"><label>上级分类：</label>
                </div>
                <div class="col-md-7">
                    <select name="upid"  data-container="body"  id="j_pid" class="selectpicker show-tick" data-style="btn medium bg-green" data-width="auto">
                        <option value="0">无</option>
                        <volist name="list" id="cat">
                            <option value="{$cat.catid}" <if condition="$cat['catid'] eq $info['upid']" >selected</if>>{$cat.pre}{$cat.catname}</option>
                        </volist>
                    </select>
                </div>
            </div>
            <div class="form-row">
                <div class="form-label col-md-2"><label>状态：</label>
                </div>
                <div class="col-md-7">
                    <select name="status"  data-container="body"  id="j_status" class="selectpicker show-tick validate[required]" data-style="btn medium bg-green" data-width="auto">
                        <option <eq name="info.status" value="1" >selected</eq> value="1">启用</option>
                        <option <eq name="info.status" value="0" >selected</eq> value="0">禁用</option>
                    </select>
                </div></div>
            <div class="form-row">
                <div class="form-label col-md-2"><label>会员权限：</label>
                </div>
                <div class="col-md-7">
                    <select name="allowpublish"  data-container="body"  id="j_enable" class="selectpicker show-tick" data-style="btn medium bg-green" data-width="auto">
                        <option <eq name="info.allowpublish" value="1" >selected</eq> value="1">会员可发布</option>
                        <option <eq name="info.allowpublish" value="0" >selected</eq> value="0">会员禁止发布</option>
                    </select>
                </div></div>
            <div class="form-row">
                <div class="form-label col-md-2"><label>分类描述：</label>
                </div>
                <div class="col-md-7">
                    <textarea class="autosize" rows="4" cols="30" name="description">{$info.description}</textarea>
                </div>
            </div>
            <div class="form-row">
                <div class="form-label col-md-2">
                    <label>分类图片：</label></div>
                <div class="col-md-7">
                    <input type="file" id="upload_picture_advspic">
                    <input type="hidden" name="img" id="cover_id_advspic" value="{$info.img}"/>
                    <div class="upload-img-box">
                        <notempty name="info['img']"><div class="upload-pre-item">
                                <img src="__ROOT__{$info.path}" width="100" height="100"/></div></notempty>
                    </div>
                </div>
            </div>
            <script type="text/javascript">
                $(function(){
                setTimeout(function(){
                $("#upload_picture_advspic").uploadify({
                "height"          : 30,
                        "swf"             : "__STATIC__/uploadify/uploadify.swf",
                        "fileObjName"     : "Picture",
                        "buttonText"      : "<span class='button-content'><i class='glyph-icon icon-picture-o'></i> 上传图片</span>",
                        "uploader"        : "{:url('File/uploadPicture',array('session_id'=>session_id()))}",
                        "width"           : 120,
                        'removeTimeout'	  : 1,
                        'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
                        "onUploadSuccess" : uploadPicture{$field.name},
                        'onFallback' : function() {
                        alert('未检测到兼容版本的Flash.');
                        }
                });
                }, 3);
                        });
                        function uploadPicture{$field.name}(file, data){
                var data = $.parseJSON(data);
                        var src = '';
                        if (data.status){
                $("#cover_id_advspic").val(data.id);
                        src = data.url || data.path
                        $("#cover_id_advspic").parent().find('.upload-img-box').html(
                        '<div class="upload-pre-item"><img src="' + src + '" width="100" height="100" onclick="imgpop(this)"/></div>'
                        );
                } else {
                alertMsg.error(data.info);
                }
                }
            </script>
            <div class="actionBar">
                <div class="form-input col-md-10 col-md-offset-2">
                    <button type="submit" class="btn medium bg-blue">保存</button>
                    <button type="button" url="{:url('Categories/index')}" class="btn-close btn medium bg-red mrg15L">取消</button>
                </div>
            </div>
        </div>
    </form>
</block>